package com.blockmeta.bbs.immodule.adapter;

import androidx.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.blockmeta.bbs.baselibrary.base.adapter.BaseAdapter;
import com.blockmeta.bbs.baselibrary.utils.LoadPicUtil;
import com.blockmeta.bbs.baselibrary.utils.TimeUtil;
import com.blockmeta.bbs.businesslibrary.arouter.RouterHelper;
import com.blockmeta.bbs.businesslibrary.arouter.RouterPath;
import com.blockmeta.bbs.immodule.R;
import com.blockmeta.bbs.immodule.bean.UserReply;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class personalHomeReplyAdapter extends BaseAdapter<UserReply.Reply, BaseViewHolder> implements View.OnClickListener{
    public personalHomeReplyAdapter(int layoutResId, @Nullable List<UserReply.Reply> data) {
        super(layoutResId, data);
    }


    @Override
    protected void convert(BaseViewHolder helper, UserReply.Reply item) {
        ImageView avatar = helper.getView(R.id.news_msg_iv_avatar);
        LoadPicUtil.loadWithPicasso(avatar,item.getAuthor_info().getAvatar());
        helper.setText(R.id.news_msg_tv_name,item.getAuthor_info().getUsername());

        helper.setText(R.id.news_msg_tv_reply, item.getMessage());
        helper.setText(R.id.news_msg_tv_content,item.getSubject());

        helper.setText(R.id.news_msg_tv_time, TimeUtil.getTimeFormatText(item.getDateline()));

        View main = helper.getView(R.id.news_msg_main);
        main.setTag(item);
        main.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        UserReply.Reply item = (UserReply.Reply) v.getTag();
        String type = item.getType() + "";

        if (type.equals("4") && item.getFid() != 121) {
            //活动
            RouterHelper.startActivity(mContext, RouterPath.ACTIVE_DETAIL_ACTIVITY,item.getTid()+"");
        } else if (type.equals("3")) {
            //悬赏
            RouterHelper.buildPath(RouterPath.BBS_REWARD_ACTIVITY)
                    .withString("tid",item.getTid()+"")
                    .navigation(mContext);
        } else if (type.equals("1")) {
            //投票
            RouterHelper.buildPath(RouterPath.BBS_VOTE_ACTIVITY)
                    .withString("tid",item.getTid()+"")
                    .navigation(mContext);
        } else if (item.getFid() == 121) {
            //AMA主题帖子
//            if (item.getActivity() == null) return;
//            final String dateStatus = FormatUtil.getDateStatus(item.getActivity().getStarttimefrom(), item.getActivity().getStarttimeto());
//            RouterHelper.buildPath(RouterPath.BBS_AMA_EXTEND_ACTIVITY)
//                    .withString("tid",item.getTid()+"")
//                    .withString(Constant.ONE,item.getActivity().getAttachurl())
//                    .withString(Constant.TWO,dateStatus)
//                    .navigation(mContext);
        } else {
            RouterHelper.buildPath(RouterPath.BBS_DETAIL_ACTIVITY).withString("tid",item.getTid()+"").navigation(mContext);
        }

    }
}
